<template>
  <div class="map-box ct">
    <div class="c-map">
      <div class="ct">
        <div class="map-t">
          <div class="map-t-l">
            <img src="../../assets/9.png" alt="">
            <div class="map-t-t">站院地图</div>
          </div>
          <img class="map-t-r" src="../../assets/8.png" alt="">
        </div>
        <div class="map-c">
          <div class="map-map">
            <div ref="eChartsRef" className="chart"></div>
          </div>
          <div class="map-tab">
            <div class="tab-head" :class="tab2=='KEJI'?'gl':''">
              <!-- <div @click="getPageCourtyard('JIDI')" class="tab-hitem cp">
                <img v-if="tab2=='JIDI'" class="hitem-img" src="../../assets/12.jpeg" alt="">
                站院联建示范基地
              </div>
              <div @click="getPageCourtyard('KEJI')" class="tab-hitem cp">
                河南科技小院
              </div> -->
              <div class="tab-hitem" @click="getPageCourtyard('JIDI')">
                农技推广站
              </div>
              <div class="tab-hitem cp" @click="getPageCourtyard('KEJI')">
                <img v-if="tab2=='KEJI'" class="hitem-img cp" src="../../assets/12.jpeg" alt="">
                站院联建示范基地
              </div>
            </div>
            <div class="tab-content">
              <el-input
                style="width: 240px"
                size="large"
                :suffix-icon="Search"
                placeholder="输入站院名称"
                class="tab-input"
              />
              <div class="tab-list">
                <el-popover 
                 :width="300"
                  popper-style="box-shadow: rgb(14 18 22 / 35%) 0px 10px 38px -10px, rgb(14 18 22 / 20%) 0px 10px 20px -15px; padding: 20px;"
                  popper-class="popper"
                  placement="right"
                  trigger="hover"
                  :show-arrow="false"	
                  :offset="40"
                  :show-after="200"
                   v-for="item in yards">
                  <template #reference>
                    <div class="tab-item" >
                      <div class="item-top">
                        <div class="top-tit">
                          {{ item.courtyardName }}
                        </div>
                        <div class="top-sta">
                          已开放
                        </div>
                      </div>
                      <div class="item-bottom">
                        <div class="bottom-name">
                          {{ item.trainingUnits }}
                        </div>
                        <div class="bottom-city">
                          {{ item.area }}
                        </div>
                      </div>
                    </div>
                  </template>
                  <template #default>
                    <div class="pop-content" @click="to('/newyardhome?yardId='+item.courtyardId)">
                      <img :src="item.photo"  alt="">
                      <div class="tit">
                        <div class="tit-l">{{ item.courtyardName }}</div>
                        <div class="tit-r">已开放</div>
                      </div>
                      <div class="tit-text">
                        培养单位：{{ item.trainingUnits }}
                      </div>
                      <div class="tit-text">
                        共建单位：{{ item.coUnit }}
                      </div>
                      <div class="tit-text tit-texts">
                        <div>专家： {{ item.manager }}</div>
                        <div>所属地区：{{ item.area }}</div>
                      </div>
                      <div class="tit-text">
                        主要农产品：{{ item.agriculturalProducts }}
                      </div>
                    </div>
                  </template>
                </el-popover>

              </div>
            </div>
          </div>
        </div>
        <div class="map-b">
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
  import { ref, onMounted } from 'vue';
	import henanMap from '../../assets/henanMap.json';
	import * as eCharts from "echarts";
  import { getCityMap, pageCourtyard } from '@/api/home'
	import { Search } from '@element-plus/icons-vue';
	import { useRouter } from 'vue-router'

	const router = useRouter()

	const eChartsRef = ref(null);
  onMounted(() => {
		getMapCensusRegisterLocation1();
	})
  const getMapCensusRegisterLocation1 = () => {
    // let vData =[ {
    //   value: 20,
    //   name: '南阳市'
    // }];
    // const myChart = eCharts.init(eChartsRef.value);
    // myChart.clear();
    // mapFunction(vData,myChart);

		// const data = {
		// 	page: {
		// 	"pageNum": 0,
		// 	"pageSize": 0,
		// 	},
		// 	params: {
		// 	}
		// }
		getCityMap().then(res => {
			console.log('aqew123123',res)
			let vData = [];
      for (let item of Object.keys(res.data)) {
        let value = {value: res.data[item], name: item.trim()}
        vData.push(value)
      }
			const myChart = eCharts.init(eChartsRef.value);
			myChart.clear();
			mapFunction(vData,myChart);
		})
	}

    // 科技小院
    const yards = ref([]);
  const tab2 = ref('JIDI');

  const getPageCourtyard =  async(courtyardType) => {
    tab2.value = courtyardType;

    const params = {
      params: {
        status: true,
        courtyardType,
      },
      page: {
        pageSize: 1000,
        pageNum: 0,
      }
    }
    const ret = await pageCourtyard(params)
    yards.value = ret?.data?.list || [];
  }
  getPageCourtyard('KEJI');

  // 地图
  const mapFunction = (vData,myChart) => {
    eCharts.registerMap('henan', JSON.stringify(henanMap));
    let map = {
      title: {text: "",},
      tooltip: { trigger: 'item' },
      visualMap: {
        show: false,
        text: ['多', '少'],
        realtime: false,
        calculable: true,
        inRange: {
          color: ['#56A669','#56A669', '#56A669','#56A669','#56A669','#56A669']
        }
      },
      series:[
        {
          name: '小院数量',
          type: "map",
          map: 'henan',
          data: vData,
          zoom: 1.2,
          // layoutCenter: ['50%', '50%'],
          // layoutSize: 120,
          label:{
            normal:{
              show:true,
              textStyle:{
                fontSize:10
              },
            },
          },
          itemStyle:{
            areaColor:'#CCC',
            // width: 1000
          },
          emphasis:{// 对应的鼠标悬浮效果
            label:{
              textStyle:{color:"#FFFFFF"},
            },
            itemStyle:{
              areaColor:'#CCC',
            }
          },
        },
      ]
    }
    myChart.setOption(map);
  }


  const to = (path) => {
		// router.push(path)
    window.open(`/#${path}`)

	}
</script>
<style lang="scss" scoped>
.map-box {
  flex: 1;
  width: 100%;
  padding: 0 10%;
  .c-map {
    width: 100%;
    height: 1080px;
    background: url('../../assets/10.jpg') no-repeat top left / 100% 100%;
    .ct {
      display: flex;
      flex-direction: column;
      height: 100%;
    }
    .map-t {
      height: 190px;
      width: 100%;
      padding-left: 88px;
      display: flex;
      align-items: center;
      padding-top: 100px;
      .map-t-l {
        img {
          width: 85px;
        }
        .map-t-t {
          font-size: 48px;
          font-weight: 900;
          color: #000;
        }
      }
      .map-t-r {
        width: 110px;
        margin-left: 65px;
      }
    }
    .map-c {
      flex: 1;
      overflow: hidden;
      display: flex;
      padding-right: 20px;
      justify-content: space-between;
      .map-map {
        height: 100%;
        flex: 1;
        .chart {
          width: 100%;
          height: 100%;
        }
      }
      .map-tab {
        height: 100%;
        width: 450px;
        display: flex;
        flex-direction: column;
        margin-left: 50px;
        .tab-head {
          height: 100px;
          margin-bottom: 15px;
          border-radius: 10px;
          display: flex;
          align-items: center;
          background: url('../../assets/11.png') no-repeat center center / 100% 100%;
          // background-color: #2fa962;

          color: #333;
          transform: rotateY(180deg);

          .tab-hitem {
            flex: 1;
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            display: flex;
            flex-direction: column;
            justify-content: center;
          transform: rotateY(-180deg);
          font-size: 18px;
            .hitem-img {
              width: 50px;
              margin-bottom: 10px;
            }
            &:last-child {
              color: #333;
            }
          }
          &.gl {
            background-image: url(../../assets/23.png);
            .tab-hitem {
              color: #333;

            }
            .tab-hitem:last-child {
              color: #fff;
            }
          }
        }
        .tab-content {
          flex: 1;
          overflow: hidden;
          background-color: #2fa962;
          border-radius: 15px;
          display: flex;
          flex-direction: column;
          padding: 15px 0;
          .tab-input {
            height: 50px;
            width: 100% !important;
            padding: 0 10px;
            :deep(.el-input__wrapper) {
              border-radius: 10px;
              font-size: 20px;
            }
          }
          .tab-list {
            flex: 1;
            overflow: hidden scroll;
            padding: 0 15px 0 10px;
          }
          .tab-item {
            width: 100%;
            height: 95px;
            background: #fff;
            margin-top: 10px;
            border-radius: 10px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            font-size: 20px;

            .item-top {
              display: flex;
              align-items: center;
              justify-content: space-between;
              width: 100%;
              padding: 0 12px;
              color: #000;
              .top-tit {
                font-size: 24px;
                font-weight: bold;
                flex: 1;
              }
              .top-sta {
                width: 65px;
                height: 28px;
                border-radius: 15px;
                background-color: #068043;
                color: #fff;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 14px;
              }
            }
            .item-bottom {
              display: flex;
              align-items: center;
              justify-content: space-between;
              width: 100%;
              padding: 0 12px;
              margin-top: 10px;
              color: #333;
              font-size: 18px;
            }
          }
        }
      }
    }
    .map-b {
      width: 100%;
      height: 100px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      font-size: 24px;
      color: #666;
      cursor: pointer;
    }
  }
}
</style>